package com.ruoyi.product.controller;

import com.ruoyi.business.domain.product.TbProductSkus;
import com.ruoyi.business.service.product.TbProductSkusService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商品SKU表Controller
 */
@RequiredArgsConstructor
@RestController
@RequestMapping("/business/product/skus")
@Api(tags = "商品SKU管理接口")
public class TbProductSkusController extends BaseController {

    private final TbProductSkusService tbProductSkusService;

    /**
     * 查询商品SKU列表
     */
//    @SaCheckPermission("business:product:skus:list")
    @GetMapping("/list/{productId}")
    @ApiOperation("根据商品查询SKU列表")
    public R<List<TbProductSkus>> list(@PathVariable("productId") Long productId) {
        List<TbProductSkus> list = tbProductSkusService.selectSkusList(productId);
        return R.ok(list);
    }

    /**
     * 获取商品SKU详细信息
     */
//    @SaCheckPermission("business:product:skus:query")
    @GetMapping(value = "/{id}")
    @ApiOperation("获取商品SKU详情")
    public R<TbProductSkus> getInfo(@PathVariable("id") Long id) {
        return R.ok(tbProductSkusService.selectSkusById(id));
    }

    /**
     * 新增商品SKU
     */
//    @SaCheckPermission("business:product:skus:add")
    @PostMapping
    @ApiOperation("新增商品SKU")
    public R<Boolean> add(@RequestBody TbProductSkus tbProductSkus) {
        return tbProductSkusService.insertSkus(tbProductSkus);
    }

    /**
     * 修改商品SKU
     */
//    @SaCheckPermission("business:product:skus:edit")
    @PutMapping
    @ApiOperation("修改商品SKU")
    public R<Boolean> edit(@RequestBody TbProductSkus tbProductSkus) {
        return R.ok(tbProductSkusService.updateSkus(tbProductSkus));
    }

    /**
     * 删除商品SKU
     */
//    @SaCheckPermission("business:product:skus:remove")
    @DeleteMapping("/{ids}")
    @ApiOperation("删除商品SKU")
    public R<Boolean> remove(@PathVariable Long[] ids) {
        return R.ok(tbProductSkusService.deleteSkusByIds(ids));
    }
}
